//COMMON UTILITIES

String.prototype.startsWith = function(str) {
	return (this.match("^" + str) == str)
}

function log(msg) {
	if (typeof (console) != "undefined") {
		console.log(msg);
	}
}

function htmlEncode(value) {
	if (value) {
		return $('<div/>').text(value).html();
	} else {
		return '';
	}
}

function validateNumber(n) {
	n = $.trim(n);
	n = parseInt(n, 10);
	if (isNaN(n))
		n = 0;
	return n;
}

function formatDateTimeHours(date) { 
	var n = date.getHours();
	return date.toDateString()+" "+(n < 10 ? "0" + n : n)+":00"
}

function formatDateTime(date) { 
	var n = date.getHours();
	var m = date.getMinutes();
	return formatDate(date)+" "+(n < 10 ? "0" + n : n)+":"+(m < 10 ? "0" + m : m)
}

function formatDate(date) {
	var y = date.getFullYear();
	var m = date.getMonth()+1;
	var d = date.getDate();
	return (m < 10 ? "0" + m : m)+"-"+(d < 10 ? "0" + d : d)+"-"+y;
}